/*
 * (C) 2014-2015 Alibaba Group Holding Limited
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 *
 *     __  ___   ______        ___       __          ___
 *    |  |/  /  /  __  \      /   \     |  |        /   \
 *    |  '  /  |  |  |  |    /  ^  \    |  |       /  ^  \
 *    |    <   |  |  |  |   /  /_\  \   |  |      /  /_\  \
 *    |  .  \  |  `--'  |  /  _____  \  |  `----./  _____  \
 *    |__|\__\  \______/  /__/     \__\ |_______/__/     \__\
 *
 *
 *
 */
//
// Created by KOALA TEAM on 12/19/14.
//

#import "NSString+KLRegEx.h"
#import "RegExCategories.h"

@implementation NSString (KLRegEx)

- (BOOL)kl_Match:(NSString*)regEx{
    return [RX(regEx) isMatch:self];
    
}

//邮箱
+ (BOOL)isValidEmail:(NSString*)email{
    return [email kl_Match:@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"];
}
//匹配正整数
+ (BOOL)isValidUnsignedInteger:(NSString*)numberStr{
    return [numberStr kl_Match:@"^[1-9]d*$"];
}
//　 //匹配负整数
+ (BOOL)isValidNegativeInteger:(NSString*)numberStr{
    return [numberStr kl_Match:@"^-[1-9]d*$"];
}
//　　//匹配整数
+ (BOOL)isValidSignedInteger:(NSString*)numberStr{
    return [numberStr kl_Match:@"^-?[1-9]d*$"];
}

//　 //匹配非负整数（正整数 + 0）
+ (BOOL)isValidNotNegativeInteger:(NSString*)numberStr{
     return [numberStr kl_Match:@"^[1-9]d*|0$"];
}
//　　 //匹配非正整数（负整数 + 0）
+ (BOOL)isValidNotUnsignedInteger:(NSString*)numberStr{
     return [numberStr kl_Match:@"^-[1-9]d*|0$"];
}

//匹配正浮点数
+ (BOOL)isValidUnsignedFloat:(NSString*)numberStr{
    return [numberStr kl_Match:@"^[1-9]d*.d*|0.d*[1-9]d*$"];
}
//匹配负浮点数
+ (BOOL)isValidNegativeFloat:(NSString*)numberStr{
    return [numberStr kl_Match:@"^-([1-9]d*.d*|0.d*[1-9]d*)$"];
}
//匹配浮点数
+ (BOOL)isValidFloat:(NSString*)numberStr{
    return [numberStr kl_Match:@"^-?([1-9]d*.d*|0.d*[1-9]d*|0?.0+|0)$"];
}
//匹配非负浮点数（正浮点数 + 0）
+ (BOOL)isValidNotNegativeFloat:(NSString*)numberStr{
    return [numberStr kl_Match:@"^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$"];
}
//匹配非正浮点数（负浮点数 + 0
+ (BOOL)isValidNotUnsignedFloat:(NSString*)numberStr{
    return [numberStr kl_Match:@"^(-([1-9]d*.d*|0.d*[1-9]d*))|0?.0+|0$"];
}
@end
